﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.AspNetCore.Mvc.Authorization;
using Abp.AspNetCore.Mvc.Extensions;
using FwProject.Controllers;
using FwProject.Restaurant;
using FwProject.Users;
using Microsoft.AspNetCore.Mvc;

namespace FwProject.Web.Controllers
{
    [AbpMvcAuthorize]
    public class StockCheckController : FwProjectControllerBase
    {
        public readonly IStockCheckInfoAppService _stockCheckInfoAppService;
        public readonly IUserAppService _userAppService;

        public StockCheckController(IStockCheckInfoAppService stockCheckInfoAppService, IUserAppService userAppService)
        {
            _stockCheckInfoAppService = stockCheckInfoAppService;
            _userAppService = userAppService;
        }

        public async Task<IActionResult> Index(int pageIdx,DateTime? beginTime, DateTime? endTime, string RestaurantName, string Person,int size= 0)
        {
            size=size==0?20:size;
            if (pageIdx == 0)
                pageIdx = 1;
            var usermodel = await _userAppService.GetAllPersonAsync();
            ViewBag.Person = usermodel;
            var model = await _stockCheckInfoAppService.GetPagedListAsync(pageIdx, size, beginTime, endTime, RestaurantName, Person);
            if (Request.IsAjaxRequest())
            {
                return PartialView("IndexPartial", model);
            }
            return View(model);
        }

        public async Task<IActionResult> Edit(Guid id)
        {
            var entity = await _stockCheckInfoAppService.GetEntityAsync(id);
            return View(entity);
        }

        [HttpPost]
        public async Task<IActionResult> Edit(Guid id, int CheckCount)
        {
            await _stockCheckInfoAppService.ModifyAsync(id, CheckCount);

            return Json("Success");
        }


    }
}
